package com.zdj.presentation.modules.im.adapters;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.easyrecyclerview.adapter.BaseViewHolder;
import com.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.zdj.presentation.R;
import com.zdj.presentation.common.constants.MsgViewType;
import com.zdj.presentation.databinding.ItemChatBinding;
import com.zdj.presentation.modules.im.holders.ChatViewHolder;
import com.zdj.presentation.modules.im.holders.ChatViewHolderLeft;
import com.zdj.presentation.modules.im.holders.ChatViewHolderRight;
import com.zdj.presentation.modules.im.models.ChatModel;

/**
 * Created by zdj on 16-7-9.
 */

public class ChatAdapter extends RecyclerArrayAdapter<ChatModel> {

    public ChatAdapter(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        BaseViewHolder baseViewHolder = null;
        switch (viewType) {
            case MsgViewType.IMVT_COM_MSG:
                baseViewHolder = new ChatViewHolderLeft(DataBindingUtil.inflate(layoutInflater, R.layout.chatting_item_msg_text_left, parent, false));
                break;
            case MsgViewType.IMVT_TO_MSG:
                baseViewHolder = new ChatViewHolderRight(DataBindingUtil.inflate(layoutInflater, R.layout.chatting_item_msg_text_right, parent, false));
                break;
        }
        return baseViewHolder;
    }

    @Override
    public int getViewType(int position) {
        ChatModel chatModel = getItem(position);
        if (chatModel.isComMsg) {
            return MsgViewType.IMVT_COM_MSG;
        } else {
            return MsgViewType.IMVT_TO_MSG;
        }
    }
}
